package com.yhn.weixin.utils;

import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.util.HashMap;
import java.util.Map;

public class JsoupUtil {
    public static Connection.Response getConnToUrl(String url, Map<String,String> cookies, Connection.Method method, String param,String content_type)throws Exception{
            Connection conn = Jsoup.connect(url);
        conn.header("User-Agent",
                "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0");// 配置模拟浏览器
        //"application/json; charset=UTF-8"
//        text/javascript
        Connection.Response rs  = conn
                .method(method)
                .header("Content-Type", content_type)
                .ignoreHttpErrors(true)
                .requestBody(param)
                .cookies(cookies==null?new HashMap<>():cookies)
                .timeout(120000)
                .execute();// 获取响应
        return rs;
    }
}
